#ifndef __zos_h__
#define __zos_h__
#include "zutilinc.h"

static inline int zTimeS()
{
	return (int)(::time(NULL));
}


#if ZUTIL_OSTYPE==ZUTIL_LINUX
#include <pthread.h>
#include <sys/select.h>
#include<sys/time.h>
#include <errno.h>


static inline long long zTimeMS()
{
	timeval tv;
	::gettimeofday(&tv,NULL);
	long long t;
	t=tv.tv_sec;
	t=t*1000+tv.tv_usec/1000;
	return t;
}
#endif

#if ZUTIL_OSTYPE==ZUTIL_ANDROID
#include <pthread.h>
#include <sys/select.h>
#include<sys/time.h>
#include <errno.h>


static inline long long zTimeMS()
{
	timeval tv;
	::gettimeofday(&tv,NULL);
	long long t;
	t=tv.tv_sec;
	t=t*1000+tv.tv_usec/1000;
	return t;
}
#endif

#if ZUTIL_OSTYPE==ZUTIL_WIN32
#include <winsock2.h>
#include <windows.h>
#include <assert.h>
#include <sys/timeb.h>
#include <time.h>
static inline long long zTimeMS()
{
	struct timeb tb;

	ftime(&tb);
	long long t;
	t = tb.time;
	t=t*1000+tb.millitm;
	return t;
}
static inline struct tm* localtime_r (const time_t *clock, struct tm *result) { 
	if (!clock || !result) return NULL;
	struct tm* p=localtime(clock);
	if (!p) return NULL;
	memcpy(result,p,sizeof(*result)); 
	return result; 
}
static inline struct tm* gmtime_r (const time_t *clock, struct tm *result) { 
	if (!clock || !result) return NULL;
	struct tm* p=gmtime(clock);
	if (!p) return NULL;
	memcpy(result,p,sizeof(*result)); 
	return result; 
}
char *asctime_r(const struct tm *tm, char *buf);
char *ctime_r(const time_t *timep, char *buf);
#endif

#endif
